<?php include("header.php"); ?>

<?php
include("functions/database.php"); 
$idcheck = base64_decode($_POST['edit_id']); 
$passcheck = $_POST['Password']; 

$sqlcheck = mysqli_query($con,"SELECT * FROM DonateList WHERE Password='$passcheck' AND ID='$idcheck' LIMIT 1"); 
if(mysqli_num_rows($sqlcheck) == 1){ ?>
<!-- Edit Entry Page -->

    <article>
      <header><h1>Edit Entry</h1>
        <p>Placeholder Text:</p>
      </header>

      <header class="huge">
        <?php
        $result = mysqli_query($con,"SELECT * FROM DonateList WHERE ID='$idcheck'");
        $data = mysqli_fetch_array($result) ?>
        <form action="functions/edit.php?id=<?php echo base64_encode($data['ID']) ?>" method="post">
        <input type="text" name="Name" id="donate-name" value="<?php echo $data['Name'] ?>" />
        <input type="text" name="Contact" id="donate-contact" value="<?php echo $data['Contact'] ?>" />
        <input type="text" name="Location" id="donate-location" value="<?php echo $data['Location'] ?>" />
        <textarea name="Details" id="donate-donating"><?php echo $data['Details'] ?></textarea>

        <h6 class="quarter"></h6>
        <input type="submit" id="submitbutton" class="callbutton huge">
        <a href="index.php" class="callbutton huge">I want to go back.</a>
        <h6 class="quarter"></h6><h6 class="quarter"></h6>
        </form>
      </header>
    </article>

    <?php include("footer.php"); ?>

<?php } else { ?>

    <!-- Wrong Password Page -->
    <article>
      <header><h1>Wrong Password</h1>
		<p>The password you entered is incorrect.</p>
        <p>We'll just automatically redirect you to the <a href="index.php">main page</a> in 10 seconds.</p>
        <script>
             setTimeout(function () { 
				$("html").animate({ opacity: 0, backgroundColor: '#000' }, function() {
					window.location.href= './index.php'; 
				})
			},10000);
        </script>
      </header>
    </article>

    <?php include("footer.php"); ?>

<?php } ?>